<?
class ControllerModuleAdvertisement extends Controller {
	protected function index() {
		$this->data['template'] = $this->config->get('config_template');
		$this->language->load('module/advertisement');
		$this->load->model('fido/advertisement');
		$this->data['heading_title'] = $this->language->get('heading_title');
		$this->data['text_vote'] = $this->language->get('text_vote');
		$this->data['text_total_votes'] = $this->language->get('text_total_votes');
		$this->data['text_no_votes'] = $this->language->get('text_no_votes');
		$this->data['text_no_logo'] = $this->language->get('text_no_logo');
		$results = $this->model_fido_advertisement->getActiveAdvertisement();
		$this->load->model('tool/image');
		$this->data['logos']=array(); 
		foreach ($results as $result){
			$cfg_media_objects	= array(
			'swf'			=>	'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="[_WIDTH_]" height="[_HEIGHT_]">
									<param name="movie" value="[_FILENAME_]">
									<param name="quality" value="high">
									<embed src="[_FILENAME_]" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="[_WIDTH_]" height="[_HEIGHT_]"></embed>
								</object>'
			);
			if ( @substr($result["logo_file"], -4) == '.swf' ){
				if (substr($result["logo_file"], 0, 7) != 'http://'){
					$result["logo_file"]		= HTTP_IMAGE . $result["logo_file"];
				}
				$swf_width	= $result['logo_width'];
				$swf_height	= $result['logo_height'];
				$image		= str_replace("[_FILENAME_]", $result["logo_file"], $cfg_media_objects['swf']);
				$image		= str_replace("[_WIDTH_]", $swf_width, $image);
				$image		= str_replace("[_HEIGHT_]", $swf_height, $image);
			}
			else{
				
				if ( $result["logo_width"] || $result["logo_height"] ){
					if ($result['logo_file'] && file_exists(DIR_IMAGE . $result['logo_file'])) {
						$cfg_image = $this->model_tool_image->resize($result['logo_file'], $result["logo_width"], $result["logo_height"]);
					} else {
						$cfg_image = $this->model_tool_image->resize('no_image.jpg', $result["logo_width"], $result["logo_height"]);
					}
				}
				else{
					if ($result['logo_file'] && file_exists(DIR_IMAGE . $result['logo_file'])) {
						$cfg_image = $this->model_tool_image->resize($result['logo_file'], 200, 200);
					} else {
						$cfg_image = $this->model_tool_image->resize('no_image.jpg', 200, 200);
					}
				}
				$image='<img src="'.$cfg_image.'" title="'. $result['site_name'] .'">';				
			}
			$this->data['logos'][] = array(
				'logo_id'    	=> $result['logo_id'],
				'logo'   	 	=> $image,
				'hits'			=> $result['hits'],
				'href'			=> $result['site_url'],
				'name'			=> $result['site_name']				
				
			);
		}		
//		
		$this->id       = 'advertisement';
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/advertisement.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/advertisement.tpl';
		} else {
			$this->template = 'default/template/module/advertisement.tpl';
		}
		$this->render();
	}
	protected function updateHits(){
		$logo_id=$this->request->get['logo_id'];
		$this->load->model('fido/advertisement');
		$this->model_fido_advertisement->updateHits($logo_id);
		$logo_info=$this->model_fido_advertisement->getAdvertisementData($logo_id);
		//if($logo_info){
		$this->response->setOutput($logo_info['site_url']);
		//}else{
			
		//}
	}
}
?>
